namespace Vlog.Db.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using Vlog.DataModels;

    internal sealed class Configuration : DbMigrationsConfiguration<Vlog.Db.ApplicationDbContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(Vlog.Db.ApplicationDbContext context)
        {
            context.Posts.AddOrUpdate( p => new {p.Title, p.Content},
                new Post(){ Title="New Post", Content="This is my First Post", Date=DateTime.Now.AddDays(-5) },
              new Post(){ Title="New Post", Content="This is my 2nd Post", Date=DateTime.Now.AddDays(-3) },
              new Post(){ Title="New Post", Content="This is my 3rd Post", Date=DateTime.Now.AddDays(-1) },
              new Post(){ Title="New Post", Content="This is my 4th Post", Date=DateTime.Now.AddDays(1) }
                );
            context.SaveChanges();
            context.Comments.AddOrUpdate( c => c.Content,
                    new Comment() { Content="First!", Date=DateTime.Now, PostId=1},
                    new Comment() { Content="Excellent SIr!", Date=DateTime.Now, PostId=1},
                    new Comment() { Content="2nd!!!!", Date=DateTime.Now, PostId=2},
                      new Comment() { Content="Yay!!!!", Date=DateTime.Now, PostId=2},  
                      new Comment() { Content="First!", Date=DateTime.Now, PostId=3},  
                      new Comment() { Content="First!", Date=DateTime.Now, PostId=4}
                );
            context.SaveChanges();
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
    }
}
